﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TaskLib;

namespace TaskView
{
    public partial class TaskEditForm : Form
    {
        private readonly Task task = null;

        public enum EditMode
        {
            NewlyCreated,
            EditExisting,
            MarkingComplete
        }

        public string Description
        {
            get { return descriptionTextBox.Text; }
            set { descriptionTextBox.Text = value; }
        }

        public DateTime Scheduled
        {
            get { return scheduledDateTimePicker.Value;  }
            set
            {
                if (value >= scheduledDateTimePicker.MinDate && value <= scheduledDateTimePicker.MaxDate)
                {
                    scheduledDateTimePicker.Value = value;
                }
            }
        }

        public DateTime Completion
        {
            get { return completedDateTimePicker.Value; }
            set 
            {
                if (value >= completedDateTimePicker.MinDate && value <= completedDateTimePicker.MaxDate)
                {
                    completedDateTimePicker.Value = value;
                }
            }
        }

        public bool Completed
        {
            get { return completedCheckBox.Checked; }
            set { completedCheckBox.Checked = value; }
        }

        public string Comment
        {
            get { return commentTextBox.Text; }
            set { commentTextBox.Text = value; }
        }

        public TaskEditForm(EditMode mode, Task task = null)
        {
            this.task = task;
            InitializeComponent();

            EnableState();

            //switch (mode)
            //{
            //    case EditMode.NewlyCreated:
            //        completedDateTimePicker.Enabled = false;
            //        completedCheckBox.Enabled = false;
            //        completedLabel.Enabled = false;
            //        break;
            //    case EditMode.EditExisting:                
            //        completedDateTimePicker.Enabled = false;
            //        completedCheckBox.Enabled = false;
            //        completedLabel.Enabled = false;
            //        break;
            //    //case EditMode.MarkingComplete:
            //    //    scheduledDateTimePicker.Enabled = false;                    
            //    //    scheduledLabel.Enabled = false;
            //    //    descriptionLabel.Enabled = false;
            //    //    descriptionTextBox.Enabled = false;
            //    //    break;


            //}

            if (this.task != null)
            {
                Description = task.Description;
                Scheduled = task.Scheduled;
                Completed = task.Completed;
                Comment = task.Comment;
                Completion = task.Completion;
            }
        }

        private void descriptionTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void scheduledDateTimePicker_ValueChanged(object sender, EventArgs e)
        {

        }

        private void commentTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void completedDateTimePicker_ValueChanged(object sender, EventArgs e)
        {

        }

        private void completedCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            EnableState();
        }

        private void EnableState()
        {
            completedDateTimePicker.Enabled = completedCheckBox.Checked;
        }
    }
}
